// pages/mine/withdrawalp/withdrawalp.js
const app = getApp(),
    globalData = app.globalData,
    api = require("../../../api/index"),
    testdata = require("testdata.js"),
    utils = require('../../../utils/util');
    const http = require('../../../utils/http.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    txType: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMyWithdrawal()
  },

  async getMyWithdrawal(){
   let res = await api.balance.getMyBalance()
    let data = res.data.ResData
    console.log(data);
    this.setData({
        myWithdrawalAmount: data.Amount
    })
   
},
    // 提现
    play(){
        
        let that=this
        let token=wx.getStorageSync('token')
        console.log(token);
        let obj={
            amount: Number(that.data.txType) 
        }
        console.log(isNaN(obj.amount));
        if (isNaN(obj.amount)) {
            wx.showModal({
                showCancel:false,
                content: "请输入正确的金额哦！",
                success () {
                   that.setData({
                       txType:null
                   })
                  
                }
              })
          }else{
            if(that.data.txType==null||that.data.txType<100){
                wx.showModal({
                    showCancel:false,
                    content: "提现金额不能小于100元哦！",
                    success () {
                       that.setData({
                           txType:null
                       })
                      
                    }
                  })
            }else{
                http.request('POST', '/user/withdrawal',obj).then((res)=>{
                    console.log(res);
                      wx.showModal({
                          showCancel:false,
                          content: res.data.ErrMsg,
                          success () {
                             that.setData({
                                 txType:null
                             })
                          }
                        })
                  })
            }
          }
    },

  tx_type(e){
    // console.log(e.currentTarget.dataset.type)
    // this.setData({
    //   txType: e.currentTarget.dataset.type
    // })
    if(!this.data.txType){
      wx.showToast({
        title: '请输入大于0的金额',
        icon: 'error',
        duration: 2000
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})